<#include "/common/layout.html">
<@body>
<body class="gray-bg">
	<div class="wrapper">
	  <section class="content">
	    <div class="row">
	      <div class="col-xs-12">
	        <div class="box">
	         <div class="form-inline">
	          <div class="box-header">
	            <#if shiro.hasPermission("addAd")>
		            <div class="input-group">
		            	<a class="btn btn-sm btn-primary dialogFull" href="javascript:;" data-title="创建轮播" data-url="/mall/adv/add"><i class="fa fa-plus"></i> 创建轮播</a>
		            </div>
	            </#if>
	        	<div class="input-group input-group-sm">
	               <input type="text" name="search_value" id="search_value" class="form-control" placeholder="名称查询">
	               <div class="input-group-btn">
	                 <a href="javascript:;" id="search_data" class="btn btn-default" ><i class="fa fa-search"></i> 搜索</a>
	                 <a href="javascript:;" id="search_refresh" class="btn btn-default"><i class="fa fa-refresh"></i> 重置</a>
	               </div>
	            </div>
	          </div>
	         </div>
	         <div class="box-body">
	            <table id="adv_initTable" class="table table-bordered table-hover">
	            </table>
	         </div>
	        </div>
	      </div>
	    </div>
	  </section>
	</div>
</body>
</@body>
<script>
	$(function(){
	　　	initTable();
	}); 
	var query_data = {
		search: ''
	}
	//搜索
	$("#search_data").off().on("click", function() {
		query_data.search = $("#search_value").val();
		reloadTable();
	});
	//重置
	$("#search_refresh").off().on("click", function() {
		query_data.search = "";
		$("#search_value").val("");
		reloadTable();
	});
	//重新加载表格
	function reloadTable() {
		var oSetting = data_oTable.settings()[0];
		oSetting.ajax.data = query_data;
		data_oTable.draw();
	}
	//渲染表格
	function initTable() {
		var options = {
			id: "adv_initTable",
			ajax: {
				url: "/mall/adv/listPage",
				type: "POST",
				data: query_data,
			},
			headerCallback: function(e, a, t, n, s) {
				e.getElementsByTagName("th")[0].innerHTML = '<label class="m-checkbox"><input type="checkbox" class="minimal m-group-checkable" value="root"></label>';
				$(e.getElementsByTagName("th")).parent().css("background-color", "#f7f7fa");
			},
			columnDefs: [{
				targets: 0,
				width: "30px",
				orderable: !1,
				render: function(e, a, t, n) {
					return '<label class="m-checkbox"><input type ="checkbox" class="minimal m-checkable" value="' + t.adId + '"></label>';
				}
			},{
				targets: 1,
				title: "行号",
				orderable: !1,
				render: function(e, a, t, n) {
					return n.row+1;
				}
			},{
				targets: 2,
				title: "标题",
				orderable: !1,
				render: function(e, a, t, n) {
					if (t.adName != null) {
						return t.adName;
					} else {
						return "";
					}
				}
			},{
				targets: 3,
				title: "链接地址",
				orderable: !1,
				render: function(e, a, t, n) {
					if (t.linkUrl != null) {
						return t.linkUrl;
					} else {
						return "";
					}
				}
			},{
				targets: 4,
				title: "图片",
				orderable: !1,
				render: function(e, a, t, n) {
					return $.table.imageView(t.adUrl);
				}
			},{
				targets: 5,
				title: "所属位置",
				orderable: !1,
				render: function(e, a, t, n) {
					if (t.position == 1) {
						return '<font color="green">首页</font>';
					} else {
						return '<font color="red">详情页</font>';
					}
				}
			},{
				targets: 6,
				title: "开始时间",
				orderable: !1,
				render: function(e, a, t, n) {
					if (t.startTime != null) {
						return t.startTime;
					} else {
						return "";
					}
				}
			},{
				targets: 7,
				title: "结束时间",
				orderable: !1,
				render: function(e, a, t, n) {
					if (t.endTime != null) {
						return t.endTime;
					} else {
						return "";
					}
				}
			},{
				targets: 8,
				title: "是否启动",
				orderable: !1,
				render: function(e, a, t, n) {
					if (t.enabled == 1) {
						return '<font color="green">启动</font>';
					} else {
						return '<font color="red">关闭</font>';
					}
				}
			},{
				targets: 9,
				title: "操作",
				orderable: !1,
				render: function(e, a, t, n) {
					var html = '';
						html += '<div>'
						<#if shiro.hasPermission("editAd")>
							html += '<a class="btn btn-primary btn-xs dialogFull" href="javascript:void(0);" data-title="编辑轮播" data-url="/mall/adv/edit/'+ t.adId +'"><i class="fa fa-pencil"></i>编辑</a>'
						</#if>	
						<#if shiro.hasPermission("deleteAd")>
							html += ' <a class="btn btn-danger btn-xs" delete-url="/mall/adv/delete" data-id="'+ t.adId +'"><i class="fa fa-trash"></i>删除</a>'
						</#if>
						html += '</div>';
					return html;
				}
			}]
		};
		//渲染表格
		data_oTable = $.table.init(options);
	}
</script>